﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Frame.Lib.Core.User;
using Frame.Lib.Utilities;
using Frame.Lib.Core.Tree;

public partial class Common_DeptUserDlg : PageSelectTree
{
    private UserBO user = new UserBO();

    /// <summary>
    /// 是否单选
    /// </summary>
    private bool IsSingleSelect
    {
        get
        {
            if (string.IsNullOrEmpty(Request["SingleSelect"]))
            {
                return false;
            }
            else
            {
                return bool.Parse(Request["SingleSelect"]);
            }
        }
    }

    /// <summary>
    /// 是否允许选择部门
    /// </summary>
    private bool AllowCheckDept
    {
        get
        {
            if (string.IsNullOrEmpty(Request["AllowCheckDept"]))
            {
                return !IsSingleSelect;                
            }
            else
            {
                return bool.Parse(Request["AllowCheckDept"]);
            }
        }
    }
  

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            //if (IsSingleSelect)
            //{
            //    tvList.Attributes.Add("onclick", "SingleSelect()");
            //}

            //if (AllowCheckDept)
            //{
            //    tvList.Attributes.Add("onclick", "MultiSelect()");//一般允许选择部门就不可能是单选
            //}

            BindTree();
           
        }
    }

    private void BindTree()
    {
        //List<int> lstSelectIDs = StrUtil.SplitToInt(RestoreIDs);
        //user.BindDeptUserTree(tvList, AllowCheckDept,lstSelectIDs);

        List<TreeInfo> list = user.GetDeptUserList();

        StringBuilder sb = new StringBuilder();

        foreach (TreeInfo info in list)
        {
            sb.Append("{ id: " + info.ID + ", pId: " + info.UpperID + ", name: '" + info.Name + "'");

            if (info.UpperID == 0)
            {
                sb.Append(",open:true");
            }
          
            if (AllowCheckDept == false)
            {
                if (info.ID > 0)
                {
                    sb.Append(",nocheck: true");
                }
            }

            sb.Append("},");


        }

        lblJson.Text = sb.ToString().TrimEnd(',');

    }
}
